<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/1/28
 * Time: 10:40
 */
namespace Admin\Controller;
class NativeController extends AdminController
{
    /*
     * 土货活动列表
     */
    public function index(){

        $model   =   D('native_products_activity');
        /* 查询条件初始化 */
        if($_REQUEST['status']){//开启状态
            if($_REQUEST['status']==1){
                $map['status']=array('eq',1);
                $status=1;
            }elseif($_REQUEST['status']==2){
                $map['status']=array('eq',0);
                $status=2;
            }else{
                $status=-1;
            }
        }
        else{
            $status=-1;
        }
		//方案状态
		if($_REQUEST['type']){//开启状态
            if($_REQUEST['type']==1){
                $map['type']=array('eq',1);
                $type=1;
            }elseif($_REQUEST['type']==2){
                $map['type']=array('eq',0);
                $type=2;
            }else{
                $type=-1;
            }
        }
        else{
            $type=-1;
        }
        $this->assign('status',$status);
        $this->assign('type',$type);
		if($_REQUEST['province']){//省
            $map['province']=array('like',"%".trim($_REQUEST['province'])."%");
        }
        if($_REQUEST['city']){//城市
            $map['city']=array('like',"%".trim($_REQUEST['city'])."%");
        }
        if($_REQUEST['native_products']){//土特产
            $map['native_products']=array('like',"%".trim($_REQUEST['native_products'])."%");
        }
        if($_REQUEST['mobile']){//手机号
            $map['mobile']=array('eq',trim($_REQUEST['mobile']));
        }
        if ($_REQUEST['add_time']) {
            $time=strtotime($_REQUEST['add_time']);
            $start_time=mktime(00,00,00,date('m',$time),date('d',$time),date('Y',$time));
            $end_time=mktime(23,59,59,date('m',$time),date('d',$time),date('Y',$time));
            $map['add_time'] = array('between',"$start_time,$end_time");
        }
        if(!$map){
            $map=array();
        }
        $list = $this->lists($model,$map,'support_num desc');
        foreach($list as $key=>$val){
            $whre_follow['id']=$val['user_id'];
            $follow=M('follow')->field('nickname')->where($whre_follow)->find();
            $list[$key]['nickname']=$follow['nickname'];
        }
        $this->assign('list',$list);
        $this->display();
    }
    public function click_like(){
        $m=M('native_products_support');
        if($_REQUEST['activity_id']){//省
            $where['activity_id']=array('eq',$_REQUEST['activity_id']);
        }
        if(!$where) {
            $where = array();
        }
        $list = $this->lists($m,$where,'');
        foreach($list as $key=>$val){
            $activity_id['id']=array('eq',$val['activity_id']);
            $result=   D('native_products_activity')->field('mobile')->where($activity_id)->find();
            $list[$key]['mobile']=$result['mobile'];
            $whre_follow['id']=$val['user_id'];
            $follow=M('follow')->field('nickname')->where($whre_follow)->find();
            $list[$key]['nickname']=$follow['nickname'];
        }
        $this->assign('list',$list);
        $this->display();
    }
    //删除土货活动数据
    public function delete(){
        $ids    =   I('request.ids');
        $m=M('native_products_activity');
        if(is_array($ids)){
            $where = 'id in('.implode(',',$ids).')';
        }else{
            $where=array('id'=>$ids);
        }
        if($m->where($where)->delete()){
            $this->success("删除成功");
        }else{
            $this->error("删除失败");
        }
        // return parent::setStatus('Gphproje
    }
}